var type_id = "{$typeid}";
if(type_id=='{$typeid}'){
    type_id = $("[name='type_id']").val();
}
$('.channel-list .radio-label input').on('click',function(){
    ajax_get_suit_price('', '', 1);
});
$('.stock-offer-tabnav .tabnav-item').on('click',function(){
    var list = ajax_get_calendar_number('',true);
    if(list.length>0){
        var obj = $('.tabnav-item');
        obj.removeClass('selected');
        $(this).addClass('selected');
        if($(this).hasClass('price-set')){
            $('.number-container').hide();
            $('.price-container').show();
        }else{
            $('.price-container').hide();
            $('.number-container').show();
        }
    }else{
        ST.Util.showMsg('请先设置库存',5,1000);
    }
});
$('#number_set_btn').click(function(){
    var suit_id = $(".public_suit_id").val();
    if(!suit_id || suit_id=='')
    {
        ST.Util.showMsg('请先保存套餐',5,1000);
        return;
    }
    CHOOSE.setSome('设置总库存', {maxHeight:500,width:540,loadWindow:window,loadCallback:ajax_get_calendar_number}, '/supplier/pc/product/quote/dialog_edit_all_suit_number?suit_id='+suit_id+'&type_id='+type_id,1)
});
/****************************日历库存部分开始********************************/
function clearNumber()
{
    var suit_id = $(".public_suit_id").val();
    if(!suit_id){
        return false;
    }
    ST.Util.confirmBox("提示","清除总库存，同时会清除套餐对应的所有渠道报价，确定清除吗？",function(){
        $.ajax({
            data:{suit_id:suit_id,type_id:type_id},
            dataType:'json',
            type:'post',
            url:web_host + '/supplier/pc/product/quote/ajax_clear_number',
            success:function (data) {
                ST.Util.showMsg('清除库存成功',4,1000);
                $('.number_container').hide();
            }
        })
    });
}

/*获取日历库存*/
function ajax_get_calendar_number(data,status)
{
    if(status){
        var suit_id = $(".public_suit_id").val();
        var out = [];
        $.ajax({
            data: {suit_id:suit_id,type_id:type_id,y:data.y,m:data.m},
            dataType: 'json',
            type: 'post',
            async:false,
            url:   '/supplier/pc/product/quote/ajax_get_calendar_number',
            success: function (result) {
                out = result.data.list;
                if(!data.y && result.status && result.data.list.length>0){
                    number_calendar_init(result.data);
                    $('.number_container').show();
                }
            }
        })
        return out;
    }
}

/*日历库存切换*/
function calendarNumberCallback(date)
{
    var data = {y:date.getFullYear(),m:date.getMonth()+1};
    return ajax_get_calendar_number(data,true);
}

/*库存日历初始化*/
function number_calendar_init(mockData) {
    $.CalendarPrice({
        // 显示日历的容器
        el: '.number_container',
        // 设置开始日期
        // 可选参数，默认为系统当前日期
        startDate: mockData.starttime,
        // 可选参数，默认为开始日期相同的1年后的日期
        // 设置日历显示结束日期
        //  endDate: '2018-09',
        // 初始数据
        data: mockData.list,
        //点击单个日期,修改报价
        everyday: function (data) {
            edit_number(data);
        },
        // 配置需要设置的字段名称，请与你传入的数据对象对应
        config: [
            {
                key:'number',
                name:'总库存'
            }
        ],
        // 配置在日历中要显示的字段
        show: [
            {
                key:'number',
                name:'总库存'
            }
        ],
        // 自定义风格(颜色)
        style: {
        }
    });
}
function edit_number(data)
{
    var suit_id = $(".public_suit_id").val();
    CHOOSE.setSome('设置总库存',
        {
            maxHeight:500,
            width:540,
            loadWindow:window,
            loadCallback:set_single_day_number
        },
        web_host+'/supplier/pc/product/quote/dialog_edit_single_suit_number?suit_id='+suit_id+'&date='+data.date+'&type_id='+type_id,1)
}
//修改日历某天的显示数据
function set_single_day_number(data,status)
{
    if(data['number'])
    {
        data.number = data.number=='-1'?'不限':data.number;
        var html = '<p class="item"><span class="attr">库存</span><span class="num">'+data.number+'</span></p>';
        $('.number_container .calendar-table-wrapper td[data-id=' + data.date + '] .data-hook').html(html)
    }
    else
    {
        $('.number_container .calendar-table-wrapper td[data-id='+data.date+'] .data-hook').html('')
    }

}
/****************************日历库存部分结束********************************/
